package instanceoff;

public class InstanceOfDemo {

	public static void main(String[] args) {
		ClassA a = new ClassA();
//		ClassB b = new ClassB();
		ClassC c = new ClassC();
		ClassM m = new ClassM();
		X x;
		
		x=a;
		if (x instanceof ClassA) {
			ClassA ax = (ClassA) x;
			System.out.println(ax);
		}
		
		if (a instanceof ClassC) {
			ClassC ca = (ClassC) a;
			System.out.println(ca);
		}
		
		if (a instanceof X) {
			X xxx = (X) a;
			System.out.println(xxx);
		}
		
		if (c instanceof X) {
			X xc = (X) c;
			System.out.println(xc);
			if (xc instanceof ClassM) {
				ClassM mxc = (ClassM) xc;
				System.out.println(mxc);
			}
		}
		
//		if (m instanceof ClassA) {
//			ClassA ma = (ClassA) m;
//			System.out.println(ma);
//		}
		
		if (m instanceof X) {
			X mx = (X) m;
			System.out.println(mx);
		}
		
	}
	
	interface X { }
	
	static class ClassA implements X{ }
	
	static class ClassB extends ClassA { }
	
	static class ClassC extends ClassA { }
	
	static class ClassM {} 
}
